# -*- coding: utf-8 -*-
# https://blog.csdn.net/ronon77/article/details/84897551
# https://blog.csdn.net/heyh_py/article/details/82377744

from functools import lru_cache


@lru_cache()
def add(x, y):
    print("calculating: %s + %s" % (x, y))
    return x + y

# 自己
@lru_cache(maxsize=1)                               # maxsizi不生效
def add_1(x, y):
    print("calculating: %s + %s" % (x, y))
    return x + y


print(add(1, 2))
print(add(1, 2))
print(add(2, 3))

# 输出结果：
# calculating: 1 + 2
# 3
# 3
# calculating: 2 + 3
# 5
# 从结果可以看出，当第二次调用 add(1, 2) 时，并没有真正执行函数体，而是直接返回缓存的结果。


print(add_1(1, 2))
print(add_1(3, 2))
print(add_1(4, 2))
print(add_1(4, 2))
print(add_1(4, 2))


